#include<stdio.h>

void Swap(int* num1, int* num2)
{
	int temp = *num1;
	*num1 = *num2;
	*num2 = temp;
}

void SelectSort(int* nums, int numsSize)
{
	int begin = 0;
	int end = numsSize - 1;
	while (begin < end)
	{
		int max_index = end;
		int min_index = begin;
		for (int i = begin; i <= end; i++)
		{
			if (nums[i] < nums[min_index])
				min_index = i;
			if (nums[i] > nums[max_index])
				max_index = i;
		}
		Swap(&nums[begin], &nums[min_index]);
		if (begin == max_index)
			max_index = min_index;
		Swap(&nums[end], &nums[max_index]);
		begin++;
		end--;
	}
}

int main()
{
	int nums[] = { 9,3,5,2,7,8,6,-1,9,4,0 };
	int len = sizeof(nums) / sizeof(int);
	SelectSort(nums ,len);
	for (int i = 0; i < len; i++)
		printf("%d ", nums[i]);
	printf("\n");
	return 0;
}